<% @page_title = "Search book" %>
<%= stylesheet_link_tag "default/common", :media => "all" %>
<%= stylesheet_link_tag "default/search-book", :media => "all" %>

<div class="title"><span class="title_icon search "><%=image_tag("search-icon.png") %></span>Search book</div>
<div class='clear'></div>
<div class="search-book">
	<div class='form'>
		<%= form_tag({:controller => "default/book", :action => "search"}, :method => 'get') do |f| %>
		<p>
			<%= text_field_tag(:keyword) %>&nbsp;
			<%= select_tag(:cate, options_for_select([['Title', 0], ['Author', 1], ['Category', 2], ['Publisher', 3]], -1)) %>&nbsp;
			<%= submit_tag "Search", :name => 'search' %>
		</p>
		<% end %><!-- End form -->
	</div><!-- End .form -->
	<% if flash[:notice] %>
		<h3><%= flash[:notice] %></h3>
	<% end %>
	
	<% if @results_list %>
		<br /><hr style="color: #FAA53B" /><br />
		<div class="title"><span class="title_icon search "><%=image_tag("search-icon.png") %></span>Results</div>
		<div class='clear'></div>
		<% if @results_list.size > 0 %>
			<div class='results-list'>
				<% for result in @results_list %>
				<div class='book'>
				<% 
					order = @results_list.index(result)
					if params[:page] 
						page = params[:page].to_i - 1 
					else 
						page = 0 
					end 
				%>
					<p class='first'><strong><%= (order + page*@results_list.per_page + 1) %>&nbsp;&nbsp;<%= link_to highlight(result.title, @keyword), :controller => 'default/book', :action => 'view', :id => result.id %></strong></p>
					<div class='image'>
						<%= link_to image_tag(result.image_url), :controller => 'default/book', :action => 'view', :id => result.id %>
					</div>
					<div class='info'>
						<p><label><b>Available&nbsp;</b></label>:&nbsp;<%= result.free_quantity %></p>
						<p><label><b>Author&nbsp;</b></label>:&nbsp;<%= highlight(result.author, @keyword) %></p>
						<p><label><b>Category&nbsp;</b></label>:&nbsp;<%= highlight(BookCategory.getBookCateName(result.book_category_id), @keyword) %></p>
						<p><label><b>Publisher&nbsp;</b></label>:&nbsp;<%= highlight(result.publisher, @keyword) %></p>
					</div><!-- End .info -->
				</div><!-- End .book -->
				<% end %>
			</div><!-- End .results-list -->
		<% end %>
		<%= will_paginate @results_list %>
	<% end %>
</div><!-- End .search-book-form -->
